import {
  RECEIVE_CURRENT_USER,
  RECEIVE_ADMIN_LIST,
  RECEIVE_CONTENT_LIST
} from './mutation-types'

import {
  reqUserInfo,
  reqAdminList,
  reqContentList,
  reqContentDetail
} from '../api'

export default {
  async getAdminList({commit}) {
    const result = await reqAdminList()
    if (result.code === 0) {
      const adminList = result.data
      console.log(adminList)
      commit(RECEIVE_ADMIN_LIST, {adminList})
    }
  },

  async getContentList({commit}, page) {
      let offset = 0
      if (page) {
          offset = page.off
      }
      console.log(offset)
      const result = await reqContentList(offset);
      if (result.code === 0) {
          const contentList = result.data
          commit(RECEIVE_CONTENT_LIST, {contentList})
      }
  },

  async getUserInfo({commit, id}) {
    const result = await reqUserInfo(id);

    if (result.code === 0) {
      const userInfo = result.data
      commit(RECEIVE_CURRENT_USER, {userInfo})
    }
  }
}
